package com.sam.im.sms.app;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lqr.emoji.IImageLoader;
import com.lqr.emoji.LQREmotionKit;
import com.sam.im.greendao.DaoMaster;
import com.sam.im.greendao.DaoSession;
import com.sam.im.sms.setting.SMSSettingImpl;

/**
 * 描述
 * liuyucheng
 * Created By 刘育成 on 2019/6/3.
 */
public class MyApp extends Application {
    private static MyApp mApp;
    private static Context sContext;
    private static DaoSession sDaoSession;
    public static MyApp getInstance() {
        return mApp;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;
        MyApp.sContext = mApp.getApplicationContext();
        initDBb(MyApp.sContext);
        SMSSettingImpl.init(MyApp.sContext);
        LQREmotionKit.init(this, new IImageLoader() {
            @Override
            public void displayImage(Context context, String path, ImageView imageView) {
                Glide.with(context).load(path).centerCrop().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
            }
        });
    }

    private void initDBb(Context context) {
        DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(context, "sms.db", null);
        SQLiteDatabase db = openHelper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        sDaoSession = daoMaster.newSession();
    }
    public static DaoSession getDaoSession() {
        return sDaoSession;
    }
}
